package com.syni.mdd.sjb.common.datatreaure.controller.protect;


import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckUserIdentity;
import com.syni.mdd.sjb.common.component.utils.common.utils.DateTimeUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.RequestParamUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.common.component.utils.common.utils.RpcResponseVo;
import com.syni.mdd.sjb.common.component.utils.feign.dto.mddAll.apiPay.WxPayPrepayDto;
import com.syni.mdd.sjb.common.component.utils.feign.service.mddAll.PayRestService;
import com.syni.mdd.sjb.common.datatreaure.controller.BaseController;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.BaseRqVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.index.DataVo;
import com.syni.mdd.sjb.common.datatreaure.service.DxshAppNewsService;
import com.syni.mdd.sjb.common.datatreaure.service.impl.DxshAppIndexServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cfx
 * @since 2020-04-20
 */
@RestController
@RequestMapping("/index")
public class IndexController extends BaseController {

    @Autowired
    DxshAppIndexServiceImpl dxshAppIndexService;

    @Autowired
    DxshAppNewsService dxshAppNewsService;

    @Autowired
    PayRestService payRestService;

    /*@Autowired
    OrdersService ordersService;*/

    @PostMapping("/data")
    @ApiOperation(value = "电享生活商户端App首页")
    @CheckUserIdentity
    public Map<String,Object> data(@RequestBody @Validated DataVo dataVo){
        return dxshAppIndexService.data(dataVo);
    }


    @PostMapping("/getUnreadMessage")
    @ApiOperation(value = "获取未读消息条数")
    @CheckUserIdentity
    public Map<String,Object> getUnreadMessage(@RequestBody @Validated BaseRqVo baseRqVo){
        return dxshAppNewsService.getUnreadMessage(baseRqVo);
    }




    @GetMapping("/test")
    @ApiOperation(value = "电享生活商户端App首页")
    public Map<String,Object> test(){
        DataVo dataVo = new DataVo();
        dataVo.setLocalDateTime(DateTimeUtils.converDateToLocalDateTime(new Date(0)));
        WxPayPrepayDto wxPayPrepayDto = new WxPayPrepayDto();
        wxPayPrepayDto.setOrderNo(UUID.randomUUID().toString().replaceAll("-",""));
        wxPayPrepayDto.setBody("默认");
        wxPayPrepayDto.setAttach("默认");
        wxPayPrepayDto.setTotalAmt("1000");
        wxPayPrepayDto.setNotifyUrl("http://localhost:8293/dxshapp/index/test1");
        RpcResponseVo rpcResponseVo = payRestService.wxPayPrepay(wxPayPrepayDto);
        if(rpcResponseVo.isSuccess()){
            Map<String,Object> data = (Map<String, Object>) rpcResponseVo.getData();
            return ResultMapHelper.success(data);
        }
        return ResultMapHelper.success(dataVo);
    }

    @PostMapping("/test1")
    @ApiOperation(value = "电享生活商户端App首页")
    public Map<String,Object> test1(){
        HttpServletRequest request = RequestParamUtils.getRequest();
        Map<String,String> forWardPayData = RequestParamUtils.getWxPayData(request);
        return ResultMapHelper.success(null);
    }


    /*@GetMapping("/commitOrder")
    public Map<String,Object> commitOrder(){
        ordersService.commitOrder();



        return ResultMapHelper.success(null);
    }*/
}
